﻿using Microsoft.Extensions.DependencyInjection;

namespace D.Util.UtilCache
{
    /// <summary>
    /// 提供 Redis 做缓存处理
    /// </summary>
    public static class CacheUtil
    {
        /// <summary>
        /// 添加Redis缓存中间件
        /// </summary>
        /// <param name="services"></param>
        /// <param name="redisConn">redis链接字符串</param>
        public static void AddRedis(this IServiceCollection services, string ip, string port = "6379", string pwd = "", string defaultDatabase = "2")
        {
            if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(port))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Redis ip/port不可为空");
            } 
        }

        /// <summary>
        /// 添加缓存中间件
        /// </summary>
        /// <param name="services"></param>
        /// <param name="redisConn">redis链接字符串</param>
        public static void AddMemory(this IServiceCollection services)
        { 
            services.AddSingleton<ICacheService, CacheService>();
        }
    }
}
